<!-- 学生修改密码 -->

<template>
  <div class="main" style="padding: 50px;box-sizing: border-box">
    <el-card class="box" style="width: 500px;margin: 0 auto">
      <el-form label-width="120px" size="small" :model="form" :rules="rules" ref="pass">
        <el-form-item label="原密码" prop="password">
          <el-input v-model="form.password" autocomplete="off" show-password clearable></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="newPassword">
          <el-input v-model="form.newPassword" autocomplete="off" show-password clearable></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="confirmPassword">
          <el-input v-model="form.confirmPassword" autocomplete="off" show-password clearable></el-input>
        </el-form-item>
      </el-form>
      <div style="text-align: center">
        <el-button type="primary" @click="save">确定</el-button>
        <el-button type="warning" @click="resetForm">重置</el-button>
        <el-button type="success" @click="$router.push('/System_StuExam')">返回</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "StuResetPassword",
  data() {
    return {
      form: {},
      Student: localStorage.getItem("Student") ? JSON.parse(localStorage.getItem("Student")) : {},
      rules: {
        password: [
          {required: true, message: '请输入原密码', trigger: 'blur'},
          {min: 1, max: 12, message: '密码不能超过12个字符', trigger: 'blur'}
        ],
        newPassword: [
          {required: true, message: '请输入新密码', trigger: 'blur'},
          {min: 1, max: 12, message: '密码不能超过12个字符', trigger: 'blur'}
        ],
        confirmPassword: [
          {required: true, message: '请确认新密码', trigger: 'blur'},
          {min: 1, max: 12, message: '密码不能超过12个字符', trigger: 'blur'}
        ]
      }
    }
  },
  created() {
    this.form.username = this.Student.username
  },
  methods: {
    save() {
      this.$refs['pass'].validate((valid) => {
        if (valid) {
          if (this.form.newPassword !== this.form.confirmPassword) {
            this.$message.error("两次输入密码不一致！")
            return false;
          }
          this.request.post("/student/password", this.form).then(res => {
            console.log(res.code)
            if (res.code === 'code_200') {
              this.$message.success("密码修改成功！")
              this.$router.push('/System_StuExam')
            }
          })
        }
      });
    },
    resetForm() {
      this.$refs['pass'].resetFields()
    }
  }
}
</script>

<style scoped>
.main {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  background-image: url('../assets/02.jpg');
  background-size: cover;
}

.box {
  padding: 10px;
  border-radius: 10px;
  background: rgba(223, 219, 219, 0.2);
  box-shadow: 0 25px 35px rgba(0, 0, 0, 0.8);
}

.el-button{
  box-shadow: 3px 3px 3px rgba(0, 0, 0, .2);
}
</style>